package com.briup.web.controller;

import com.briup.pojo.Customer;
import com.briup.response.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author by ca
 * @date 2024-11-06  11:09
 */
@RestController
public class SessionController {


    @PostMapping("login3")
    public Result<String> login(HttpServletRequest request) {
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        Customer customer = new Customer();
        customer.setName(name);
        customer.setPassword(password);
        HttpSession session = request.getSession();
        System.out.println(session);
        session.setAttribute("customer", customer);
        return Result.success();
    }

    @GetMapping("getSession")
    public Result<String> getSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        System.out.println(session);
        Customer customer = (Customer) session.getAttribute("customer");
        System.out.println(customer);
        return Result.success();
    }
}
